<?php
/*
+--------------------------------------------------------------------------
|	transfer.php
|   ========================================
|	Core functions for the PayOffline Gateway	
+--------------------------------------------------------------------------
*/
/*
//////////////////////////
// PayOffline GATEWAY
//////////////////////////
// L@@K AT ALL THE LOVELY 
// VARIABLES WE HAVE TO
// PLAY WITH!!
//////

//////////////////////////
// IN THE REPEATED REGION
//////
$orderInv['productId']						- product id as an integer
$orderInv['name']							- product name as a varchar
$orderInv['price']							- price of each product (inc options)
$orderInv['quantity']						- quantity of products as an integer
$orderInv['product_options']				- products attributes as test
$orderInv['productCode']					- product code as a varchar
$i											- This is the current incremented integer starting at 0

/////////////////////////
// FIXED VARS
///////
$cart_order_id							    - cart order id as a varchar
$ccUserData[0]['email']						- Customers email address
$ccUserData[0]['title']						- Customers title (Mr Miss etc...)
$ccUserData[0]['firstName']					- Customers first name
$ccUserData[0]['lastName']					- Customers last name 
$ccUserData[0]['add_1']						- Invoice Address line 1
$ccUserData[0]['add_2']						- Invoice Address line 1
$ccUserData[0]['town']						- Invoice Town or city
$ccUserData[0]['county']					- Invoice County or state
$ccUserData[0]['postcode']					- Invoice Post/Zip Code
$ccUserData[0]['country']					- Invoice country Id we can look up the country name like this
										countryName($ccUserData[0]['country']);
$ccUserData[0]['phone']						- Contact phone no
$ccUserData[0]['mobile']					- Mobile/Cell phone number

$basket['delInf']['title']				- Delivery title (Mr Miss etc...)
$basket['delInf']['firstName']			- Delivery customers first name
$basket['delInf']['lastName']			- Delivery customers last name 
$basket['delInf']['add_1']				- Delivery Address line 1
$basket['delInf']['add_2']				- Delivery Address line 1
$basket['delInf']['town']				- Delivery Town or city
$basket['delInf']['county']				- Delivery County or state
$basket['delInf']['postcode']			- Delivery Post/Zip Code
$basket['delInf']['country']			- Delivery  country Id we can look up the country name like this	
									countryName($basket['delInf']['country']);


$basket['subTotal'] 					- Order Subtotal (exTax and Shipping)
$basket['grandTotal']					- Basket total which has to be paid (inc Tax and Shipping).
$basket['tax']							- Total tax to pay
$basket['shipCost']						- Shipping price
////////////////////////////////////////////////////////
*/

$module = fetchDbConfig("PayOffline");

function repeatVars(){
		return FALSE;
}

function fixedVars(){

	global $module, $basket, $ccUserData, $cart_order_id, $config, $GLOBALS;
	
	$hiddenVars = "<input type='hidden' name='instId' value='".$module['acNo']."' />
	                <input type='hidden' name='sign' value='".md5($module['acNo'].$cart_order_id.$basket['grandTotal'].$module['password'])."' />
					<input type='hidden' name='cartId' value='".$cart_order_id."' />
					<input type='hidden' name='MC_OID' value='".$cart_order_id."' />
					<input type='hidden' name='amount' value='".$basket['grandTotal']."' />
					<input type='hidden' name='currency' value='".$config['defaultCurrency']."' />
					<input type='hidden' name='desc' value='Cart - ".$cart_order_id."' />
					<input type='hidden' name='name' value='".$ccUserData[0]['title']." ".$ccUserData[0]['firstName']." ".$ccUserData[0]['lastName']."' />
					<input type='hidden' name='RetURL' value='".$GLOBALS['storeURL']."/cart.php?act=step2&mode=emptyCart' />
					<input type='hidden' name='storeurl' value='".$GLOBALS['storeURL']."' />";
					
					if(!empty($ccUserData[0]['add_2'])){

						$add = $ccUserData[0]['add_1'].",&#10;".$ccUserData[0]['add_2'].",&#10;".$ccUserData[0]['town'].", ".$ccUserData[0]['county'].",&#10;".countryName($ccUserData[0]['country']);
					
					} else {
						
						$add = $ccUserData[0]['add_1'].",&#10;".$ccUserData[0]['town'].",&#10;".$ccUserData[0]['county'].",&#10;".countryName($ccUserData[0]['country']);
					
					}
					
					$hiddenVars .= "<input type='hidden' name='address' value='".$add."' />
					<input type='hidden' name='postcode' value='".$ccUserData[0]['postcode']."' />
					<input type='hidden' name='country' value='".countryIso($ccUserData[0]['country'])."' />
					<input type='hidden' name='tel' value='".$ccUserData[0]['phone']."' />
					<input type='hidden' name='email' value='".$ccUserData[0]['email']."' />";
				
				if($module['testMode']>0){	
					$hiddenVars .= "<input type='hidden' name='testMode' value='".$module['testMode']."' />";
				}
				
			return $hiddenVars;
			
}

function successFirst(){
	if( isset($_POST['MC_OID']) && $_POST['transStatus']=="Y"){
	
		return TRUE;
	
	} else {
	
		return FALSE;
	
	}

}

function success(){
		if($_GET['f']==1){
		
			return FALSE;
			
		} else {
		
			return TRUE;
			
		}	

}

///////////////////////////
// Other Vars
///////////////////////////
$formAction = "http://secure.PayOffline.com/CubeCart/Invoice.aspx";
$formMethod = "post";
$formTarget = "_self";
$transfer = "auto";
$stateUpdate = TRUE;

?>